<?php

    $servername = "localhost";
    $username = "root";
    $password = "root123";
    $dbname = "oopdb";

    try{
        $conn = new mysqli($servername, $username, $password, $dbname);

    }
    catch (Exception $e){
        die('连接失败：'.$e->getMessage());
    }


//    $conn = new mysqli($servername, $username, $password,$dbname);
    if ($conn->connect_error) {
        die("连接失败：".$conn->connect_error);
    }
    echo "连接成功！",PHP_EOL;

//  插入数据
//    $fishname = "这是''草鱼";
//    $fishname = $conn->real_escape_string($fishname);
    $insert = "INSERT INTO fish(name,weight,kind)
                values
                ('".$fishname."1"."',28,'鲤科'),
                ('$fishname.2',28,'鲤科'),
                ('$fishname.3',28,'鲤科'),
                ('湖鳟',11,'鲑科'),
                ('虹鳟',9,'鲑科')
                ";

    if ($conn->query($insert) === true){
        echo "数据插入成功！";
    } else {
        echo '插入错误：'.$insert. PHP_EOL . $conn->error;
    }


    $conn->close();
?>